package	com.sdry.web.controller.newAdd;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.llm.Item;
import com.sdry.model.lz.Customer;
import com.sdry.model.newAdd.Finance;
import com.sdry.model.newAdd.Handle;
import com.sdry.model.newAdd.Receivable;
import com.sdry.model.zc.ZcSysUserEntity;
import com.sdry.service.llm.ItemService;
import com.sdry.service.newAdd.HandleService;
import com.sdry.service.newAdd.ReceivableService;
import com.sdry.service.tdd.OthersService;
import com.sdry.utils.ResponseUtil;
/**
 *
 *@ClassName: ReconciliationController
 *@Description: 对账管理
 *@Author tdd
 *@Date 2019-07-10 11:47:25
 *@version 1.0
*/
@Controller
@RequestMapping("/reconciliation")
public class ReconciliationController{
	@Resource ReceivableService receivableService;
	@Resource HandleService handleService;
	@Resource OthersService othersService;
	@Resource ItemService itemService;
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/recReport")
	public String recReport (Model model,HttpSession session) {
		//获取当前操作人
		ZcSysUserEntity su = (ZcSysUserEntity)session.getAttribute("user");
		Long customer_id = su.getCustomer_id();
		model.addAttribute("customer_id",customer_id);
		
		Customer param = new Customer();
		List<Customer> customers = othersService.customerQueryAllByMution(param);
		model.addAttribute("customers",customers);
		Item item = new Item();
		List<Item> items = itemService.queryAllByMution(item );
		model.addAttribute("items",items);
		return "/newAdd/recReport";
	}
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	 */
	@RequestMapping("/payReport")
	public String payReport (Model model,HttpSession session) {
		//获取当前操作人
		ZcSysUserEntity su = (ZcSysUserEntity)session.getAttribute("user");
		Long customer_id = su.getCustomer_id();
		model.addAttribute("customer_id",customer_id);
		
		Customer param = new Customer();
		List<Customer> customers = othersService.customerQueryAllByMution(param);
		model.addAttribute("customers",customers);
		Item item = new Item();
		List<Item> items = itemService.queryAllByMution(item );
		model.addAttribute("items",items);
		return "/newAdd/payReport";
	}
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	 */
	@RequestMapping("/finReport")
	public String finReport (Model model,HttpSession session) {
		//获取当前操作人
		ZcSysUserEntity su = (ZcSysUserEntity)session.getAttribute("user");
		Long customer_id = su.getCustomer_id();
		model.addAttribute("customer_id",customer_id);
		
		Customer param = new Customer();
		List<Customer> customers = othersService.customerQueryAllByMution(param);
		model.addAttribute("customers",customers);
		Item item = new Item();
		List<Item> items = itemService.queryAllByMution(item );
		model.addAttribute("items",items);
		return "/newAdd/finReport";
	}
	
	
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/receivableList")
	public void receivableList(Receivable param,HttpServletResponse response) throws Exception{
		// 条件分页查询内容
		List<Receivable> list = receivableService.findReportPageByMution(param);
		// 条件查询总条数
		Integer total = receivableService.selectCountByMution(param);
		// 转为json数据传至页面
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		ResponseUtil.write(response, jsonObject);
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/handleList")
	public void handle(Handle param,HttpServletResponse response) throws Exception{
		// 条件分页查询内容
		List<Handle> list = handleService.findReportPageByMution(param);
		// 条件查询总条数
		Integer total = handleService.selectCountByMution(param);
		// 转为json数据传至页面
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		ResponseUtil.write(response, jsonObject);
	}
	/**
	 * 财务报表条件分页查询
	 * @param page 页数
	 * @param pageSize 每页条数
	 * @param client_id 客户
	 * @param type 查询类型  dd当天  hh24小时内  week 本周  month 本月   year本年   quarter本季度
	 * @param id 项目id
	 * @param create_date 日期
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/financeList")
	public void finance(int page,int pageSize
			,Long client_id,String type,Long id,String create_date,HttpServletResponse response) throws Exception{
		// 条件分页查询内容
		List<Finance> list = receivableService.findFinancePageByMution(page, pageSize, client_id, type, id,create_date);
		// 条件查询总条数
		Integer total = receivableService.selectFinanceCountByMution(client_id, type, id,create_date);
		// 转为json数据传至页面
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		ResponseUtil.write(response, jsonObject);
	}
	
}
